import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import { rules} from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
//列表数据

const isDir = (type) => type === 0;
const isMenu = (type) => type === 1;
const isButton = (type) => type === 2;

export enum ComponentTypes {
  Default = 'layouts/default/index',
  IFrame = 'sys/iframe/FrameBlank',
}

export const columns: BasicColumn[] = [
   {
    title: '菜单名称',
    align:"center",
    dataIndex: 'name'
   },
   {
    title: '菜单路径',
    align:"center",
    dataIndex: 'url'
   },
   {
    title: '菜单类型',
    align:"center",
    dataIndex: 'menuType'
   },
   {
    title: '菜单排序',
    align:"center",
    dataIndex: 'sortNo'
   },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
	{
      label: "菜单名称",
      field: 'name',
      component: 'Input',
      //colProps: {span: 6},
 	},
];
//表单数据
export const formSchema: FormSchema[] = [
  // {
  //   label: '父id',
  //   field: 'parentId',
  //   component: 'Input',
  // },
  {
    label: '菜单名称',
    field: 'name',
    component: 'Input',
  },
  {
    label: '菜单路径',
    field: 'url',
    component: 'Input',
  },
  {
    field: 'menuType',
    label: '菜单类型',
    component: 'RadioButtonGroup',
    defaultValue: 0,
    componentProps: ({ formActionType, formModel }) => {
      return {
        options: [
          { label: '一级菜单', value: 0 },
          { label: '子菜单', value: 1 },
          // { label: '按钮/权限', value: 2 },
        ],
        onChange: (e) => {
          const { updateSchema, clearValidate } = formActionType;
          const label = isButton(e) ? '按钮/权限' : '菜单名称';
          //清除校验
          clearValidate();
          updateSchema([
            {
              field: 'name',
              label: label,
            },
            {
              field: 'url',
              // required: !isButton(e),
              required: false,
            },
          ]);
          //update-begin---author:wangshuai ---date:20220729  for：[VUEN-1834]只有一级菜单，才默认值，子菜单的时候，清空------------
          if (isMenu(e) && !formModel.id && (formModel.component=='layouts/default/index' || formModel.component=='layouts/RouteView')) {
            formModel.component = '';
          }
          //update-end---author:wangshuai ---date:20220729  for：[VUEN-1834]只有一级菜单，才默认值，子菜单的时候，清空------------
        },
      };
    },
  },
  {
    field: 'parentId',
    label: '上级菜单',
    component: 'TreeSelect',
    required: true,
    componentProps: {
      //update-begin---author:wangshuai ---date:20230829  for：replaceFields已过期，使用fieldNames代替------------
      fieldNames: {
        label: 'name',
        key: 'id',
        value: 'id',
      },
      //update-end---author:wangshuai ---date:20230829  for：replaceFields已过期，使用fieldNames代替------------
      dropdownStyle: {
        maxHeight: '50vh',
      },
      getPopupContainer: (node) => node?.parentNode,
    },
    ifShow: ({ values }) => !isDir(values.menuType),
  },
  {
    label: '菜单排序',
    field: 'sortNo',
    component: 'InputNumber',
  },
  {
    label: '图片',
    field: 'icon',
    component: 'Input',
  },
  // {
  //   label: '是否叶子节点',
  //   field: 'isLeaf',
  //   component: 'Input',
  // },
  // {
  //   label: '删除状态',
  //   field: 'delFlag',
  //   component: 'InputNumber',
  // },
	// TODO 主键隐藏字段，目前写死为ID
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];

// 高级查询数据
export const superQuerySchema = {
  name: {title: '菜单名称',order: 1,view: 'text', type: 'string',},
  url: {title: '菜单路径',order: 2,view: 'text', type: 'string',},
  menuType: {title: '菜单类型',order: 3,view: 'number', type: 'number',},
  sortNo: {title: '菜单排序',order: 4,view: 'number', type: 'number',},
};

/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[]{
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}